home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / BOOT.ASM < prev    next >
Assembly Source File  |  1993-05-05  |  5KB  |  139 lines

  1. ;=======================================================================
  2. ; Computer Reboot
  3. ;
  4. ; This program performs a cold (with memory check) or warm (without
  5. ; memory check) boot.  A cold boot is just as if the computer has
  6. ; been turned off and then back on.  The memory will be checked for
  7. ; errors.  A warm boot is the same as pressing CTRL-ALT-DEL.  The
  8. ; memory is not checked for errors.  This program might be useful
  9. ; in a batch file that changes the system parameters and then must
  10. ; restart the computer.
  11. ;
  12. ; Examples:
  13. ;
  14. ;  BOOT warm
  15. ;
  16. ;    this will initiate a warm boot
  17. ;
  18. ;  BOOT cold
  19. ;
  20. ;    this will initiate a cold boot
  21. ;
  22. ; WARNING: Booting the computer erases all data that has not been
  23. ; saved to disk or some other nonvolatile source.
  24.  
  25. ;================================================
  26. ; Program entry point.
  27.  
  28.         cld                             ;forward direction
  29.         mov     si, CMD_LINE            ;get command line location 
  30.         lodsb                           ;load length and point to first byte
  31.         or      al, al                  ;check if no parameter
  32.         jz      main2
  33.  
  34.         mov     cl, al
  35.         sub     ch, ch                  ;CX has byte count
  36.  
  37. ;--- skip preceding delimiters in command line
  38.  
  39. main1   cmp     BYTE [si], ' '          ;check if space or control character
  40.         ja      main3                   ;exit loop if not
  41.         inc     si                      ;next byte
  42.         loop    main1                   ;loop back if more
  43.  
  44. ;--- illegal parameter
  45.  
  46. main2   mov     dx, OFFSET Err_Mes      ;message
  47.         mov     ah, 9                   ;DOS print function
  48.         int     21H                     ;execute
  49.  
  50.         mov     ax, 4CFFH               ;exit with error code 255
  51.         int     21H                     ;execute
  52.  
  53. ;--- found start of parameter
  54.  
  55. main3   cmp     cx, 4                   ;check if too few bytes
  56.         jb      main2                   ;jump if so, error
  57.         je      main4                   ;jump if same length
  58.         mov     cx, 4                   ;set to max length, ignore other chars
  59.  
  60. main4   push    cx
  61.         push    si
  62.  
  63. ;--- check if cold parameter
  64.  
  65.         mov     ax, COLD_BOOT           ;cold boot flag
  66.         mov     di, OFFSET Cold         ;check if cold message
  67.         call    Cmp_Str                 ;compare strings
  68.         jz      main5                   ;jump if equal, cold boot
  69.  
  70. ;--- not cold, check if warm parameter
  71.  
  72.         pop     si
  73.         pop     cx
  74.  
  75.         mov     ax, WARM_BOOT           ;warm boot flag
  76.         mov     di, OFFSET Warm         ;check if warm message
  77.         call    Cmp_Str                 ;compare strings
  78.         jnz     main2                   ;jump if not equal, error
  79.  
  80. ;--- continue with reboot, flag in ax
  81.  
  82. main5   sub     bx, bx
  83.         mov     ds, bx                  ;segment zero
  84.         mov     [RESET_FLAG], ax        ;set reset flag
  85.  
  86. ;--- the following code initializes the registers and is probably not needed,
  87. ;--- the "Intel iAPX 86/88, 186/188 User's Manual Programmer's Reference" says
  88. ;--- this is done by a hardware reset (through the ResET lines) and it does
  89. ;--- seem to work okay without it
  90.  
  91.         sub     ax, ax                  ;zero to ax
  92.         push    ax
  93.         popf                            ;clear all flags
  94.  
  95.         mov     ds, ax
  96.         mov     es, ax
  97.         mov     ss, ax                  ;clear segment regs
  98.  
  99. ;--- initiate reboot, jump to first instruction
  100.  
  101.         jmp     0, 0FFFFH               ;branch to FFFF:0000
  102.  
  103. ;================================================
  104. ; Compare two (text) strings.
  105. ;  In: DI= string one; SI= string two, which is
  106. ;   converted to lower-case; CX= bytes to check.
  107. ;  Out: ZF= set if strings are equal.
  108.  
  109. Cmp_Str PROC NEAR
  110. cmpstr1 or      BYTE [si], 'a'-'A'      ;make lower-case
  111.         cmpsb                           ;compare bytes
  112.         jne     cmpstr2                 ;jump if no match
  113.         loop    cmpstr1                 ;loop back if more to check
  114. cmpstr2 ret
  115.         ENDP                    ;Cmp_Str
  116.  
  117. ;================================================
  118. ; Program data.
  119.  
  120. ;--- parameter data
  121.  
  122. CMD_LINE        EQU    80h       ;offset of command line
  123. Cold            DB     'cold'    ;cold parameter
  124. Warm            DB     'warm'    ;warm parameter
  125.  
  126. ;--- reset flag data; note that since the flag's cleared value (cold boot) is
  127. ;--- is not defined in the BIOS data area, I used an abitrary number that is
  128. ;--- not equal to the set value; if the operating system or BIOS uses this
  129. ;--- variable for other purposes, doing a cold boot might cause unexpected
  130. ;--- results or a system crash
  131.  
  132. RESET_FLAG      EQU     0472h   ;memory offset, at segment 0
  133. COLD_BOOT       EQU     0000h   ;value to set if cold boot, <> WARM_BOOT
  134. WARM_BOOT       EQU     1234h   ;value to set if warm boot
  135.  
  136. ;--- error message
  137.  
  138. Err_Mes         DB      'BOOT: usage is BOOT WARM or BOOT COLD',13,10,'$'
  139.